package org.finesys.auth.configure;

import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Setter
@ConfigurationProperties(prefix = "security.permit-all")
public class SecurityPermitAllProperties {

    // 默认放行的url
    private final static String[] DEFAULT_URLS = {"/ws/**", "/error", "/v3/api-docs", "/actuator/**", "/token/**", "/gitee/authorize/**", "/gitee/code/**", "/configuration"};
    // 配置需要放行的url
    private String[] urls = {};

    public String[] getUrls() {
        if (urls == null || urls.length == 0) {
            return DEFAULT_URLS;
        }
        //转为数组
        List<String> list = new ArrayList<>(Arrays.asList(urls));
        //默认数组
        list.addAll(new ArrayList<>(Arrays.asList(DEFAULT_URLS)));
        //去重，防止重复配置
        list = list.stream().distinct().collect(Collectors.toList());
        this.urls = list.toArray(new String[0]);
        return urls;
    }

}
